import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import type {
  LoadingConfig,
  AdaptiveConfig,
  PaginationProps
} from "@pureadmin/table";
import { delay } from "@pureadmin/utils";
import { addDialog } from "@/components/ReDialog";
// import editForm from "./form.vue";
import { message } from "@/utils/message";
import dayjs from "dayjs";
// import { usePublicHooks } from "@/views/system/hooks";
interface FormItemProps {
  id?: string;
  region?: string;
  type?: string;
  area?: string;
  time?: string;
  violation?: string;
  description?: string;
  status?: string;
  date?: string;
  officer?: string;
}

export function useDept() {
  const title = "违规行驶线路报警";

  const formModel = ref<FormItemProps>({
    status: "0"
  });
  const date = dayjs(new Date()).format("YYYY-MM-DD");
  const columns: TableColumnList = [
    { label: "报警编号", prop: "id" },
    { label: "车辆号", prop: "licensePlate" },
    { label: "司机", prop: "driver" },
    { label: "报警类型", prop: "deviationType" },
    { label: "报警时间", prop: "deviationTime" },
    { label: "起点", prop: "location" },
    { label: "终点", prop: "route" },
    { label: "路线", prop: "route" },
    { label: "处理时间", prop: "processingTime" },
    { label: "处理人员", prop: "processor" }
  ];
  const addIcon = useRenderIcon(AddFill);
  const editIcon = useRenderIcon(EditPen);
  const delIcon = useRenderIcon(Delete);
  // // const { tagDisableStyle } = usePublicHooks();
  const rules: any[] = [
    {
      id: "R001",
      vehicleId: "V12345",
      licensePlate: "鄂A12345",
      driver: "张三",
      deviationType: "线路偏离",
      deviationTime: "2024/10/1 7:30",
      location: "武汉市洪山区XXX街道",
      description: "偏离指定运输路线",
      route: "洪山区-青山区指定线路",
      reason: "道路施工改道",
      status: "已处理",
      processingTime: "2024/10/1 8:00",
      processor: "王五"
    },
    {
      id: "R007",
      vehicleId: "V77654",
      licensePlate: "鄂G77654",
      driver: "吴九",
      deviationType: "线路偏离",
      deviationTime: "2024/10/5 16:30",
      location: "武汉市新洲区S路段",
      description: "车辆偏离指定路线, 进入禁行区",
      route: "新洲区-青山区指定线路",
      reason: "道路堵塞绕行",
      status: "已处理",
      processingTime: "2024/10/5 17:00",
      processor: "王五"
    }
  ];
  const formRef = ref();
  const dataList = ref([]);
  const loading = ref(true);
  /** 分页配置 */
  const pagination = reactive<PaginationProps>({
    pageSize: 20,
    currentPage: 1,
    pageSizes: [20, 40, 60],
    total: 0,
    align: "right",
    background: true,
    size: "default"
  });

  /** 加载动画配置 */
  const loadingConfig = reactive<LoadingConfig>({
    text: "正在加载第一页...",
    viewBox: "-10, -10, 50, 50",
    spinner: `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
      `
    // svg: "",
    // background: rgba()
  });

  /** 撑满内容区自适应高度相关配置 */
  const adaptiveConfig: AdaptiveConfig = {
    /** 表格距离页面底部的偏移量，默认值为 `96` */
    offsetBottom: 110
    /** 是否固定表头，默认值为 `true`（如果不想固定表头，fixHeader设置为false并且表格要设置table-layout="auto"） */
    // fixHeader: true
    /** 页面 `resize` 时的防抖时间，默认值为 `60` ms */
    // timeout: 60
    /** 表头的 `z-index`，默认值为 `100` */
    // zIndex: 100
  };

  function onSizeChange(val) {
    console.log("onSizeChange", val);
  }

  function onCurrentChange(val) {
    loadingConfig.text = `正在加载第${val}页...`;
    loading.value = true;
    delay(600).then(() => {
      loading.value = false;
    });
  }

  async function onSearch(newItem?: any) {
    loading.value = true;
    dataList.value = newItem ? [newItem].concat(rules) : rules;
    pagination.total = dataList.value.length;
    setTimeout(() => {
      loading.value = false;
    }, 500);
  }

  const resetForm = formEl => {
    if (!formEl) return;
    formEl.resetFields();
    onSearch();
  };
  function handleDelete(row: any) {
    console.log(row, "row");

    message(`操作成功`, { type: "success" });
    onSearch();
  }

  onMounted(() => {
    onSearch();
  });
  return {
    title,
    formModel,
    columns,
    addIcon,
    editIcon,
    delIcon,
    resetForm,
    onSearch,
    loading,
    dataList,
    pagination,
    loadingConfig,
    adaptiveConfig,
    onSizeChange,
    onCurrentChange,
    handleDelete
  };
}
